﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

public partial class admin_home : System.Web.UI.Page
{
    private CMyLink lnkNav;

    protected void Page_Load(object sender, EventArgs e)
    {
        lnkNav = new CMyLink();
        this.Controls.Add(lnkNav);
        lnkNav.Click += new EventHandler(lnkNav_Click);

        if (!IsPostBack)
        {
            InitTable(1, 20);
        }
    }

    void lnkNav_Click(object sender, EventArgs e)
    {
        InitTable(Convert.ToInt32((e as CMyLinkEventArg).Parameter), 20);
    }

    private void InitTable(int page, int count)
    {
        CCommon com = new CCommon();
        DataTable dt = com.ReadBySort(Request.QueryString["s"].ToString());
        StringBuilder sb = new StringBuilder();
        if (null != dt)
        {
            int top = page * count;
            if (top > dt.Rows.Count)
            {
                top = dt.Rows.Count;
            }
            int c = 0;
            for (int i = (page - 1) * count; i < top; i++)
            {
                if (c % 2 == 0)
                {
                    sb.Append("<tr>");
                }
                else
                {
                    sb.Append("<tr bgcolor=\"#f5f5f5\">");
                }
                sb.Append("<td>" + i.ToString() + "</td>");
                sb.Append("<td>" + dt.Rows[i]["title"].ToString() + "</td>");
                sb.Append("<td>");
                if (dt.Rows[i]["content"].ToString() == "")
                {
                    sb.Append("暂无");
                }
                else
                {
                    sb.Append("<img src=\"../" + dt.Rows[i]["content"].ToString() + "\" height=\"50px\" />");
                }
                sb.Append("</td>");                
                sb.Append("<td>");
                sb.Append("<a href=\"javascript:uploadfile(" + dt.Rows[i]["id"].ToString() + ");\">更新图片</a>&nbsp;&nbsp;");
                sb.Append("</td>");
                sb.Append("</tr>");
                c++;
            }
            this.ltlTable.Text = sb.ToString();
            this.ltlNav.Text = CNavigator.CreateNavigator(page, count, dt.Rows.Count, Page, lnkNav);
            this.upTable.Update();
        }
        else
        {
            this.ltlTable.Text = "<tr><td colspan=\"4\" align=\"center\">暂无数据</td></tr>";
            this.ltlNav.Text = CNavigator.CreateNavigator(page, count, 0, Page, lnkNav);
            this.upTable.Update();
        }
    }
}